< previous page page_220 next page >

Page 220
The results of these calculations give you the new X and Y coordinates of a point. Following the methods of previous sections, you can build a MapPixel subroutine that performs the inverse of these operations. This routine takes an output pixel and maps it back to an input pixel location. Usually this location will not lie at an integral location, so the program should use bilinear interpolation to calculate the output pixel's value.
Inverting the transformation steps is not difficult. The inverse of translation is a translation in the opposite direction. For example, to invert a translation by distances dx and dy in the X and Y directions, the program can translate by the distances dx and dy.
The inverse of rotation by an angle theta is simply a rotation by the angle -theta. Reflection is its own inverse since (Y) = Y.
The MapPixel subroutine shown in the following code performs this reverse transformation. The point (0, B) lies on the line of reflection, so MapPixel translates the line to the origin by subtracting B from the pixel's Y coordinate. The sine and cosine of the angle of rotation are calculated before MapPixel executes.
e10a6a0a59f035e870d90cca05b85fce.gif
' Map the output pixel (ix_out, iy_out) to the input
' pixel (x_in, y_in).
Private Sub MapPixel( _
    ByVal ix_out As Single, ByVal iy_out As Single, _
    ByRef x_in As Single, ByRef y_in As Single)
Dim x1 As Single
Dim y1 As Single
Dim x2 As Single
Dim y2 As Single
Dim x3 As Single
Dim y3 As Single
Dim x4 As Single
Dim y4 As Single

    ' Translate by (0, -B).
    x1 = ix_out
    y1 = iy_out - B
     
    ' Rotate by angle -theta around the origin.
    x2 = x1 * cos_theta - y1 * sin_theta
    y2 = x1 * sin_theta + y1 * cos_theta

    ' Reflect.
    x3 = x2
    y3 = -y2

    ' Rotate by angle theta around the origin.
    x4 = x3 * cos_theta + y3 * sin_theta
    y4 = -x3 * sin_theta + y3 * cos_theta

    ' Translate by (0, +B).
    x_in = x4
    y_in = y4 + B
End Sub

 
< previous page page_220 next page >